package com.overoid.diary.ui.day.edit;

import java.util.HashMap;
import com.overoid.diary.R;
import com.overoid.diary.ui.common.Constants;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

public class DayEditViewBottom02Activity extends Activity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);	
		
		setContentView(R.layout.day_edit_view_bottom02);
		
		final ImageButton dayEditBtnBottomExistPhoto =  (ImageButton)findViewById(R.id.dayEditBtnBottomExistPhoto);
		dayEditBtnBottomExistPhoto.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				DayEditActivity parentAct = (DayEditActivity)getParent();
				LinearLayout picLinear =  (LinearLayout)parentAct.findViewById(R.id.dayEditLinearPicture);
				
				picLinear.setVisibility(View.VISIBLE);
				 
				//Image 데이터 쿼리
				if(Constants.LOCAL_DEVICE_IMAGE_LIST == null){
				
					Constants.LOCAL_DEVICE_IMAGE_LIST = new HashMap<Integer,String>();
					
					Cursor c = getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
					if(c !=null && c.getCount() > 0){
						c.moveToFirst();
						for(int i=0; i < c.getCount(); i++) {
							Constants.LOCAL_DEVICE_IMAGE_LIST.put(i, c.getString(1));
			    			c.moveToNext();
			    		}
						c.close();
					}
					
				}
				
				parentAct.totalImgCnt =   Constants.LOCAL_DEVICE_IMAGE_LIST.size();
				parentAct.curentImgPositon=0;
				
				ImageButton dayEditBtnPicView=(ImageButton)parentAct.findViewById(R.id.dayEditBtnPicView);
				
				BitmapFactory.Options bitmpaOption = new BitmapFactory.Options();
				Bitmap bitmap = BitmapFactory.decodeFile(Constants.LOCAL_DEVICE_IMAGE_LIST.get(0), bitmpaOption);

				dayEditBtnPicView.setImageBitmap(bitmap);
				
				if( parentAct.curentImgPositon != 0 && parentAct.totalImgCnt > 0 ){
					((Button)parentAct.findViewById(R.id.dayEditBtnPicPre)).setVisibility(View.VISIBLE);
				}else{
					((Button)parentAct.findViewById(R.id.dayEditBtnPicPre)).setVisibility(View.INVISIBLE);
				}
				

				if( parentAct.totalImgCnt-1 > parentAct.curentImgPositon){
					((Button)parentAct.findViewById(R.id.dayEditBtnPicNext)).setVisibility(View.VISIBLE);
				}else{
					((Button)parentAct.findViewById(R.id.dayEditBtnPicNext)).setVisibility(View.INVISIBLE);
				}
			}
		});
		
		final ImageButton dayEditBtnBottomNewPhoto =  (ImageButton)findViewById(R.id.dayEditBtnBottomNewPhoto);
		dayEditBtnBottomNewPhoto.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(DayEditViewBottom02Activity.this,"나중에 구현",Toast.LENGTH_SHORT).show();
				
			}
		});
		
		final ImageButton dayEditBtnBottomDeletePhoto =  (ImageButton)findViewById(R.id.dayEditBtnBottomDeletePhoto);
		dayEditBtnBottomDeletePhoto.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				
				
			}
		});
		
		
	}
	
}